Imports Liftoff.PostSharp.Samples.Binding

' Decorating the class with the 'SupportDataBinding' attribute implements INotifyPropertyChanged and IEditableObject during
' a post-compile step using PostSharp, an enhancer framework by Gael Fraiteur (www.postsharp.org).
'
<Serializable(), SupportDataBinding()> _
Public Class Customer

#Region "Private Variables"
    Private myGuid As Guid
    Private myFirstName As String
    Private myLastName As String
    Private myTurnover As Single
    Public Const baseTurnover As Single = 1000.0
#End Region

#Region "Overrides"
    Public Overrides Function Equals(ByVal obj As Object) As Boolean
        If TypeOf obj Is Customer Then
            Return Equals(DirectCast(obj, Customer))
        Else
            Return MyBase.Equals(obj)
        End If
    End Function
    Public Overloads Function Equals(ByVal customer As Customer) As Boolean
        Dim sa As String = myLastName + myFirstName + myGuid.ToString
        Dim sb As String = customer.LastName + customer.FirstName + customer.Guid.ToString
        Return (String.Compare(sa, sb) = 0)
    End Function

    Public Overrides Function ToString() As String
        If String.IsNullOrEmpty(myLastName) Then
            Return String.Empty
        Else
            Return String.Format("{0} {1}", myLastName.ToUpper, myFirstName)
        End If
    End Function
#End Region

#Region "Constructor(s)"
    Public Sub New()
        myGuid = System.Guid.NewGuid()
        myTurnover = baseTurnover
        My.Application.Log.WriteEntry("New customer instanciated ( " + myGuid.ToString)
    End Sub
#End Region

#Region "Public Interface"
    Public Property FirstName() As String
        Get
            My.Application.Log.WriteEntry("Read FirstName")
            Return myFirstName
        End Get
        Set(ByVal value As String)
            myFirstName = value
        End Set
    End Property

    Public Property LastName() As String
        Get
            My.Application.Log.WriteEntry("Read LastName")
            Return myLastName
        End Get
        Set(ByVal value As String)
            myLastName = value
        End Set
    End Property

    Public Property Turnover() As Single
        Get
            My.Application.Log.WriteEntry("Read Turnover")
            Return myTurnover
        End Get
        Set(ByVal newValue As Single)
            myTurnover = newValue
        End Set
    End Property

    Public ReadOnly Property Guid() As String
        Get
            Return myGuid.ToString()
        End Get
    End Property
#End Region

End Class

